package com.example.administrator.myapplication;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.Map;

import app.Application;

/**
 * Created by cch on 2016/6/6.
 */
public  class MeAdapter extends BaseAdapter {
    private Context context;
    private ArrayList<Map<String,String>> data;
    public MeAdapter(Context context, ArrayList<Map<String, String>> data) {
        this.context = context;
        this.data = data;
    }

    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int position) {
        return data.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position ;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null){
            holder = new ViewHolder();
            convertView = LayoutInflater.from(context).inflate(R.layout.item,parent,false);
            holder.iv = (ImageView) convertView.findViewById(R.id.iv);
            holder.title = (TextView) convertView.findViewById(R.id.tv1);
            holder.description= (TextView) convertView.findViewById(R.id.tv2);
            convertView.setTag(holder);
        }else{
            convertView.setTag(holder);
        }
        String title = data.get(position).get("title");
        String dec = data.get(position).get("dec");
        String img = data.get(position).get("img");
        Application.universalImageLoader.displayImage(img,holder.iv,Application.options);
        holder.title.setText(title);
        holder.description.setText(dec);
        return convertView;
    }
    class ViewHolder{
        private ImageView iv;
        private TextView title,description;

    }
}
